package com.ftg.learn.chapter03.question;

import java.util.Arrays;

/**
 * @author 布衣
 */
public class Question {

    public static void reverse(int[] arr01, int start, int end) {
        for (int i = start, j = end; i < j; i++, j--) {
            int temp = arr01[i];
            arr01[i] = arr01[j];
            arr01[j] = temp;
        }

    }

    public static void reverse01(int[] arr02, int start, int edn) {
        reverse(arr02, 0, (arr02.length >> 1) - 1);
        reverse(arr02, (arr02.length >> 1) + 1, arr02.length - 1);
    }

    public static int a(int i) {
        //return 3 + a(2);
//        3 + 2+ a(1)
//        3 + 2 + 1+ a(0)
//        3+ 2 + 1 + 0 + a(-1)
        //3 + 2 + 1 + 0 + 0 + -1 + a(-2)
        //终止条件
        if (i == 1) {
            return 1;
        }
        return i + a(i - 1);
    }

    //终止条件  1 2 === 1 n = n-1+n-2
    public static int fibonacci02(int month) {
        if (month == 1 || month == 2) {
            return 1;
        }
        return fibonacci02(month - 1) + fibonacci02(month - 2);
    }

    public static void fibonacci01() {
        int month = 1;
        int f = 1;
        int s = 1;
        while (month < 10) {
            if (month == 1 || month == 2) {
                System.out.print(1 + "\t");
            } else {
                int sum = f + s;
                System.out.print(sum + "\t");
                f = s;
                s = sum;
            }
            month++;
        }
    }


}
